<script setup>
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();

onMounted(() => {
    // 检查是否有登录态
    const token = localStorage.getItem('auth-token');
    const currentRoute = router.currentRoute.value.path;

    // 如果没有登录且不在登录页面，则跳转到登录页
    if (!token && currentRoute !== '/auth/login') {
        router.push('/auth/login');
    }
    // 如果已登录且在登录页面，则跳转到 dashboard
    else if (token && currentRoute === '/auth/login') {
        router.push('/');
    }
});
</script>

<template>
    <router-view />
</template>

<style scoped></style>
